package cn.rongdao.jrkabao.ui.cashadvance.manager;

import android.app.Activity;
import android.support.v4.content.ContextCompat;
import android.view.View;

import com.mifengkong.frtools.util.FRString;
import com.mifengkong.frwidget.dialog.FRDialog;
import com.mifengkong.frwidget.dialog.FRDialogClickListener;

import java.util.List;

import cn.rongdao.jrkabao.R;
import cn.rongdao.jrkabao.bean.cashadvance.CashByCreditCardBean;
import cn.rongdao.jrkabao.bean.cashadvance.CashQuotaFullBean;
import cn.rongdao.jrkabao.bean.cashadvance.CreditAndDepositCardBean;
import cn.rongdao.jrkabao.ui.webview.WebViewActivity;
import cn.rongdao.jrkabao.util.CommonUtil;
import cn.rongdao.jrkabao.widget.DialogCashQuotaFull;
import cn.rongdao.jrkabao.widget.SelectCreditCardFromBottom;
import cn.rongdao.jrkabao.widget.SelectFeeFromBottom;

/**
 * Created by jack on 2017/12/25
 */

public class CashAdvanceCardManager {

    private SelectCreditCardFromBottom selectCreditCardFromBottom;
    private SelectFeeFromBottom selectFeeFromBottom;
    private DialogCashQuotaFull dialogCashQuotaFull;
    private OnButterConfirmClickListener onButterConfirmClickListener;

    private Activity activity;

    public CashAdvanceCardManager(Activity activity) {
        this.activity = activity;
        selectCreditCardFromBottom = new SelectCreditCardFromBottom(activity);
        selectFeeFromBottom = new SelectFeeFromBottom(activity);
    }

    public void showCashQuotaFullDialog(final CashQuotaFullBean data, boolean isTwoButton) {
        String content;
        final String buttonText;
        String buttonType = data.getConfirm().getType();
        if (isTwoButton) {
            content = data.getConfirm().getContent();
            buttonText = "";
        } else {
            content = data.getContent();
            buttonText = data.getButton_text();
        }
        new FRDialog.MDBuilder(activity)
                .setMessage(content)
                .setNegativeContentAndListener(!FRString.isEmpty(buttonText) ? buttonText : "取消", new FRDialogClickListener() {
                    @Override
                    public boolean onDialogClick(View view) {
                        if (!FRString.isEmpty(buttonText)) {
                            if (!FRString.isEmpty(data.getNext_url())) {
                                WebViewActivity.start(activity, data.getNext_url());
                            }
                        }
                        return true;
                    }
                })
                .setNegativeTextColor(ContextCompat.getColor(activity, R.color.c333333))
                .setPositiveTextColor(ContextCompat.getColor(activity, R.color.colorPrimary))
                .setPositiveContentAndListener(FRString.isEmpty(buttonText) ? (CommonUtil.isStatusSuccess(buttonType) ? "确定交易" : "更换卡") : "",new FRDialogClickListener() {
                    @Override
                    public boolean onDialogClick(View view) {
                        if (FRString.isEmpty(buttonText)) {
                            if (!CommonUtil.isStatusSuccess(data.getConfirm().getType())) {
                                CashAdvanceManagerActivity.Companion.start(activity);
                            } else if (null != onButterConfirmClickListener) {
                                onButterConfirmClickListener.onButtonConfirm();
                            }
                        }
                        return true;
                    }
                })
                .show();
    }

    public void setSelectCardAdapterList(List<CreditAndDepositCardBean> dataList) {
        if (null != dataList && dataList.size() > 0) {
            selectCreditCardFromBottom.setAdapterDataList(dataList);
            selectCreditCardFromBottom.show();
        }
    }

    public void setSelectFeeAdapterList(List<CashByCreditCardBean.PassWay> dataList, String id, String money) {
        if (null != dataList && dataList.size() > 0) {
            selectFeeFromBottom.setAdapterDataList(dataList, id, money);
            selectFeeFromBottom.show();
        }
    }

    public void setSelectCardDialogSelectedListener(SelectCreditCardFromBottom.OnDialogSelectCardClickListener onDialogSelectCardClickListener) {
        selectCreditCardFromBottom.setOnDialogSelectCardClickListener(onDialogSelectCardClickListener);
    }

    public void setSelectFeeDialogSelectedListener(SelectFeeFromBottom.OnDialogSelectCardClickListener onDialogSelectCardClickListener) {
        selectFeeFromBottom.setOnDialogSelectCardClickListener(onDialogSelectCardClickListener);
    }

    public void dismiss() {
        selectCreditCardFromBottom.dismiss();
        selectFeeFromBottom.dismiss();
    }

    public void setOnButterConfirmClickListener(OnButterConfirmClickListener onButterConfirmClickListener) {
        this.onButterConfirmClickListener = onButterConfirmClickListener;
    }

    public interface OnButterConfirmClickListener {
        void onButtonConfirm();
    }
}
